package com.tianyu.service.base;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.tianyu.mapper.DeviceMapper;
import com.tianyu.model.entity.Device;
import com.tianyu.model.ro.ServiceRo;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**********************************
 * @Author YSW
 * @Description
 * @Date 2024/7/15 - 14:28
 **********************************/

@Slf4j
@Service
public class DeviceService {

    @Resource
    private DeviceMapper deviceMapper;

    public List<Device> getList() {
        return deviceMapper.selectList(Wrappers.lambdaQuery());
    }

    public List<Device> getListByCompany(Integer ykCompanyId) {
        return deviceMapper.selectList(Wrappers.<Device>lambdaQuery().eq(Device::getYkCompanyId, ykCompanyId));
    }

    public Device selectBySn(String sn) {
        return deviceMapper.selectOne(Wrappers.<Device>lambdaQuery()
                .eq(Device::getSn, sn));
    }

    public ServiceRo<?> updateById(Device thirdCompanyAccessChannel) {
        final int update = deviceMapper.updateById(thirdCompanyAccessChannel);
        return update == 1 ? ServiceRo.resultSuccess() : ServiceRo.resultFailed("更新失败...");
    }

    public ServiceRo<?> insert(Device thirdCompanyAccessChannel) {
        final int insert = deviceMapper.insert(thirdCompanyAccessChannel);
        return insert == 1 ? ServiceRo.resultSuccess() : ServiceRo.resultFailed("更新失败...");
    }
}
